import 'package:flutter/material.dart';
import '../../provider/chatdetailprovider.dart';

class ChatdetailInputUI extends StatefulWidget {
  ChatdetailInputUI({Key? key, required this.chatDetailProvider})
      : super(key: key);

  ChatDetailProvider chatDetailProvider;

  @override
  _ChatdetailInputUIState createState() => _ChatdetailInputUIState();
}

class _ChatdetailInputUIState extends State<ChatdetailInputUI> {
  TextEditingController textController = TextEditingController();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  var focusNode = FocusNode();

  submitChat() {
    if (textController.text.trim().isEmpty) return;
    widget.chatDetailProvider.chat(textController.text);

    textController.text = "";
    focusNode.requestFocus();
  }

  @override
  Widget build(BuildContext context) {
    return Align(
      alignment: Alignment.bottomLeft,
      child: Container(
        padding: EdgeInsets.only(left: 10, bottom: 10, top: 10),
        height: 60,
        width: double.infinity,
        color: Colors.white,
        child: Row(
          children: <Widget>[
            GestureDetector(
              onTap: () {},
              child: Container(
                height: 30,
                width: 30,
                decoration: BoxDecoration(
                  color: Colors.lightBlue,
                  borderRadius: BorderRadius.circular(30),
                ),
                child: Icon(
                  Icons.add,
                  color: Colors.white,
                  size: 20,
                ),
              ),
            ),
            SizedBox(
              width: 15,
            ),
            Expanded(
              child: TextField(
                controller: textController,
                focusNode: focusNode,
                onSubmitted: (value) {
                  submitChat();
                },
                decoration: InputDecoration(
                    hintText: "请输入...",
                    hintStyle: TextStyle(color: Colors.black54),
                    border: InputBorder.none),
              ),
            ),
            SizedBox(
              width: 15,
            ),
            FloatingActionButton(
              onPressed: () {
                submitChat();
              },
              child: Icon(
                Icons.send,
                color: Colors.white,
                size: 18,
              ),
              backgroundColor: Colors.blue,
              elevation: 0,
            ),
          ],
        ),
      ),
    );
  }
}
